#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int left = 0, flag = 0, min = nums.size() + 1;
        int n = nums.size();
        int sum = nums[left];
        int len = 1;
        int x = target;
        int right = left;
        while (left < n)
        {

            while (right < n && sum < x)
            {

                right++;
                len++;
                if (right == n)break;
                sum += nums[right];

            }
            if (right < n && len < min && sum >= x && len>0)
            {
                min = len;
            }
            sum -= nums[left];
            len--;
            left++;
            if (right < n && len < min && sum >= x && len>0)
            {
                min = len;
            }
            
        }
        if (min > nums.size()) return 0;
        return min;
    }
};


class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int left = 0, right = 0, len = 0, maxlen = 0, zero = 0;
        int n = nums.size();
        while (right < n)
        {
            len++;
            if (nums[right] == 0)
                zero++;
            while (zero > k)
            {
                if (nums[left] == 0)
                {
                    zero--;
                }
                left++, len--;

            }
            right++;
            if (len > maxlen)
                maxlen = len;
        }
        return maxlen;
    }
};